/*
    kOTF Open Trace Format - a library for generating execution traces.
    Copyright 2012 Daniel K. O.

    kOTF is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    kOTF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with kOTF.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <assert.h>

#include "StreamImpl.hpp"
#include "EventBuffer.hpp"

namespace kotf {

    EventBuffer::EventBuffer(StreamImpl* s) :
        size(0),
        streamImpl(s)
    {
        assert(streamImpl);
    }

    void
    EventBuffer::write()
    {
        assert(streamImpl);
        if (size)
            streamImpl->write(this);
    }
    

    bool
    EventBuffer::add(const Event& e)
    {
        if (size == capacity)
            return false;
        data[size++] = e;
        return true;
    }

    void
    EventBuffer::reset(StreamImpl *s)
    {
        assert(s);
        size = 0;
        streamImpl = s;
    }
}
